/*
 ============================================================================
 Name        : PCB.c
 Author      : James McQueen, Corwyn Simpson, Craig Markham
 Version     :
 Date        : 05/14/2012
 Description : TCSS-422 Operating Systems Scheduler
 ============================================================================
 */
#include <time.h>
#include <stdlib.h>
#include "PCB.h"

int PID = 0;

//All registers and CPU kept track of for context switch.
// Length of process should be in process not PCB. My num_steps should
// be called my program length.  Used to set maximum size on
// of the PC.  Thus PC = PC % num_steps.

PCB* pcb_init(Process* process_ptr)
{
    PCB* this = (PCB*) malloc(sizeof(PCB));
    PID = PID + 1;
    this->PID = PID;
    this->PC = 0;
    this->my_state = READY;
    this->my_process_ptr = process_ptr;	//Pointer to the process.
    return this;
}

void pcb_destroy(PCB* pcb_ptr)
{
    free(pcb_ptr);
}
int pcb_getPID(PCB* pcb)
{
	return pcb->PID;
}
int pcb_getPC(PCB* pcb)
{
	return pcb->PC;
}
char pcb_getState(PCB* pcb)
{
	return pcb->my_state;
}
Process* pcb_getProcess(PCB* pcb)
{
	return pcb->my_process_ptr;
}
void pcb_incrementPC(PCB* pcb)
{
	pcb->PC++;
	pcb->PC = pcb->PC % pcb->my_process_ptr->my_length;
	pcb->my_process_ptr->clock_count++;

}
void pcb_setState(PCB* pcb, char state)
{
	pcb->my_state = state;
}
void pcb_setProcess(PCB* pcb, Process* process)
{
	pcb->my_process_ptr = process;
}
